angular.module('todomvc')
.directive('todoEscape', function(){
  'use strict';
  
  var ESCAPE_KEY = 27;
  
  return function(scope, elem, attrs){
    elem.bind('keydown', function(event){
      if (event.keyCode === ESCAPE_KEY) {
        scope.$apply(attrs.todoEscape);
      }
    });
    
    scope.$on('$destory', function(){
      elem.unbind('keydown')
    })
  }
})